<link rel="stylesheet" href="__STATIC__/addon/file/Huploadify.css" />
<script src="__STATIC__/addon/file/jquery.Huploadify.js"></script>

<input type="hidden" name="{$addons_data['name']}" id="{$addons_data['name']}" value="{$addons_data['value']}"/>
<div class="upload-img-box{$addons_data['name']}">
    {notempty name="$info[$addons_data['name']]"}
    <div class="upload-pre-item">
        <div style="cursor:pointer; color:red;" class="pic_del"  onclick="picDel{$addons_data.name}(this)" >
            <img src="__STATIC__/addon/file/uploadify-cancel.png" />
        </div>
        <a target="_blank" href="{$info[$addons_data['name']]|default=''|get_picture_url=$addons_data.addons_model}">
            <img  style="max-width:{$addons_config['maxwidth']};" src="{$info[$addons_data['name']]|default=''|get_picture_url=$addons_data.addons_model}"/>
        </a>
    </div>
    {/notempty}
</div>
<div id="upload_picture_{$addons_data['name']}"></div>

<script type="text/javascript">
    var maxwidth = "{$addons_config['maxwidth']}";

    $("#upload_picture_{$addons_data.name}").Huploadify({
        auto: true,
        height: 30,
        fileObjName: "file",
        buttonText: "{$addons_config['button_text']}",
        uploader: "{$addons_config['upload_url']}",
        width: 120,
        removeTimeout: 1,
        fileSizeLimit:"{$addons_config['max_size']}",
        fileTypeExts: "{$addons_config['allow_postfix']}",
        onUploadComplete: uploadPicture{$addons_data.name}
    });

    function uploadPicture{$addons_data.name}(file, data)
    {

        var data = $.parseJSON(data);

        $("#{$addons_data['name']}").val(data.path);

        var src ='__STATIC__/upload/picture/' + data.path;
        
        var src =src.replace(/\/static/g, '');

        $(".upload-img-box{$addons_data['name']}").html('<div class="upload-pre-item"> <a target="_blank" href="' + src + '"> <img style="max-width: ' + maxwidth + ';" src="' + src + '"/></a></div>');
    }

    function picDel{$addons_data.name}(obj)
    {
        var addons_name = "{$addons_data.name}";
        $("#" + addons_name).val('');
        $(obj).parent().remove();
    }

</script>